<%@ page import="java.util.List" %>
<%@ page import="java.util.Map" %>
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>处理注册/修改</title>
  <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
  <link rel="stylesheet" href="css/HandlingUsers.css">
</head>
<body>
<%@ include file="adminNavbar.jsp" %>

<div class="container mx-auto px-4 py-8">
  <h1 class="text-3xl font-bold text-gray-800 mb-6 text-center">处理注册/修改</h1>

  <div class="bg-white shadow-md rounded my-6">
    <table class="min-w-full border-collapse">
      <thead>
        <tr class="bg-gray-200 text-gray-600 uppercase text-sm leading-normal">
          <th class="py-3 px-6 text-left">类型</th>
          <th class="py-3 px-6 text-left">用户名</th>
          <th class="py-3 px-6 text-left">身份证号</th>
          <th class="py-3 px-6 text-left">邮箱</th>
          <th class="py-3 px-6 text-left">电话</th>
          <th class="py-3 px-6 text-left">密码</th>
          <th class="py-3 px-6 text-left">备注</th>
          <th class="py-3 px-6 text-center">操作</th>
        </tr>
      </thead>
      <tbody class="text-gray-600 text-sm font-light">
        <%
          List<Map<String, String>> pendingRequests = (List<Map<String, String>>) application.getAttribute("pendingRequests");
          if (pendingRequests != null && !pendingRequests.isEmpty()) {
            for (Map<String, String> requestData : pendingRequests) {
        %>
        <tr class="border-b border-gray-200 hover:bg-gray-100">
          <td class="py-3 px-6 text-left"><%= "registration".equals(requestData.get("type")) ? "注册" : "信息修改" %></td>
          <td class="py-3 px-6 text-left"><%= requestData.get("name") %></td>
          <td class="py-3 px-6 text-left"><%= requestData.get("pid") %></td>
          <td class="py-3 px-6 text-left"><%= requestData.get("email") %></td>
          <td class="py-3 px-6 text-left"><%= requestData.get("phone") %></td>
          <td class="py-3 px-6 text-left"><%= requestData.get("password") %></td>
          <td class="py-3 px-6 text-left">
            <% if ("modification".equals(requestData.get("type"))) { %>
              修改字段: <%= requestData.get("field") %>, 新值: <%= requestData.get("newValue") %>
            <% } else { %>
              无
            <% } %>
          </td>
          <td class="py-3 px-6 text-center">
            <form action="ProcessModificationServlet" method="post" class="inline">
              <input type="hidden" name="requestData" value='<%= new com.google.gson.Gson().toJson(requestData) %>'>
              <button type="submit" name="action" value="approve" class="bg-green-500 text-white px-3 py-1 rounded mr-2">批准</button>
              <button type="submit" name="action" value="ban" class="bg-red-500 text-white px-3 py-1 rounded">拒绝</button>
            </form>
          </td>
        </tr>
        <%
            }
          } else {
        %>
        <tr>
          <td colspan="8" class="py-4 px-6 text-center text-gray-500">暂无待处理请求</td>
        </tr>
        <%
          }
        %>
      </tbody>
    </table>
  </div>
</div>

<script>
  // 处理操作结果
  <%
    String result = request.getParameter("result");
    if (result != null) {
  %>
    alert("<%= "success".equals(result) ? "操作成功" : "操作失败" %>");
    <%
      if ("success".equals(result)) {
        // 刷新页面以更新表格
    %>
    window.location.href = "HandlingUsers.jsp";
    <%
      }
    %>
  <%
    }
  %>
</script>
</body>
</html>